<include file="Public:header" />
<script src="/succescms/js/jquery.js"></script>
<script type="text/javascript">
function role_lock(role_row){
	
	var name = role_row.value+"[]";
	//alert (name);
	var row = document.getElementsByName(name);
	//alert (row);
	var row_l = row.length;
	//alert (row_l);
	
//	name_str = name.replace(^[A-Za-z]\w$, "")
//	alert (name_str);



	if(role_row.checked == true){
		
		for(i = 0; i < row_l; i++){
			row[i].disabled = false;
			//document.getElementById('role_btn').disabled = false;
		}
	}
	else{
		for(i = 0; i < row_l; i++){
			row[i].disabled = true;
			//document.getElementById('role_btn').disabled = true;
		}		
	
	}

}

function chk_role(){
	//alert (document.getElementById('role_add').checked);
	//alert (document.getElementById('form1').action);
	var roles_num = 0;
	var roles_row = document.getElementsByName("roles_row[]");
	var roles_l = roles_row.length;	//news_row 长度
	var roles_arr = new Array();
	for(k = 0; k < roles_l; k++){
		if(roles_row[k].checked == true){
			roles_num++;
			roles_arr[k] = roles_row[k].value;
		}
	}
	
	if(document.getElementById('none').checked == true){
		alert ("没有选择操作!");
		return false;
	}
	else if(document.getElementById('role_del').checked == true){
		//alert ("2");
		if(roles_num == "0"){
			alert ("请选择要操作的角色!");
			return false;
		}
	}
	else if(document.getElementById('role_edit').checked == true){
		if(roles_num == "0"){
			alert ("请选择要操作的角色!");
			return false;
		}
		else{
			//alert (roles_arr);
			//alert (roles_arr.length);
			var len1 = roles_arr.length
			
			for(j = 0; j < len1; j++){
				//alert (roles_arr[j]);
				if(roles_arr[j]){
					
					var name = roles_arr[j]+"[]";
					var str = roles_arr[j]+"_result";
					var result_arr = new Array();
					//alert (name);
					//alert (document.getElementsByName(name));
					var len2 = document.getElementsByName(name).length;
					var i = 0
					
					//alert (len2);
					while(i < len2){
						//alert (document.getElementsByName(name)[i].value);
						result_arr[i] = document.getElementsByName(name)[i].value;
						i++;
					}
					document.getElementById(str).value = result_arr.toString();
					//alert (document.getElementById(str).value);
				}
			}
			//alert (document.getElementById(str).value);
			return true;
		}
	}
	else if(document.getElementById('role_add').checked == true){
		//alert ("role_add");
		if(document.getElementById('new_name').value==""){
			alert ("必须输入一个角色名!")
			return false;
		}
		else{
			//alert ("not null");
			var new_arr = new Array();	
			xx = document.getElementsByName('new_row[]');
			//alert (xx);
			for(j = 0; j < 6; j++){
				new_arr[j] = xx[j].value;
			}
			document.getElementById('new_auth').value = new_arr;
			//alert (new_arr.toString());
		}
	}
	
	
}

function auth_Cho(obj){
	if(obj.checked == true){
		obj.value = "1";
	}
	else if(obj.checked == false){
		obj.value = "0";
	}
	
}

function oper_Chk(obj2){
	//alert (obj2.value);
	var x = document.getElementById('new_tr');
	var xxx = document.getElementsByName('roles_row[]');
	document.getElementById('form1').action = "";
	document.getElementById('form1').action = "role/"+obj2.value;
	//alert(document.getElementById('form1').action);
	xxx_L = xxx.length;
	
	for(ii = 0; ii < xxx_L; ii++){
		xxx[ii].disabled = true;
		xxx[ii].checked = false;
		//xxx[ii].value = 0;
			
	}
	
	if(obj2.value == "role_add"){
		
		if(x.style.display == "none"){
			x.style.display = "";
		}

	}
	else{
		
		if(obj2.value != ""){
			
			for(ii = 0; ii < xxx_L; ii++){
				xxx[ii].disabled = false;
			}
		}

		if(x.style.display == ""){
			x.style.display = "none";
		}
		
	}
	
}

function repeat_Chk(obj3){
	sub_obj = document.getElementById('role_btn')
	
	if(obj3.value != ""){
		name_arr = document.getElementsByName('roles_row[]');
		len = name_arr.length;
		i = 0;
		j = 0;
		while(i < len){
				if(obj3.value == name_arr[i].value){
					j++;
				}
				i++;
		}
		
		if(j>0){
			sub_obj.disabled = true;
			alert("角色名不能重复!");
		}
		else{
			sub_obj.disabled = false;
		}
		
		
/*		$.post("member.php",{oper:"name_Chk",type:"role",str:obj3.value},function(s){
			if(s == "1"){
				obj3.select();
				sub_obj.disabled = true;
				alert("角色名不能重复!");
			}
			else{
				sub_obj.disabled = false;
			}
		})*/
	}
	else{
		sub_obj.disabled = false;
	}	
}

</script>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return chk_role()">
<input id="url" value="__URL__/" type="hidden">
<input type="submit" name="role_btn" id="role_btn" value ="确认">
<input type="radio" name="oper" id="none" value="" checked onclick="oper_Chk(this)">不操作&nbsp;&nbsp;
<input type="radio" name="oper" id="role_edit" value="role_edit" onclick="oper_Chk(this)">修改&nbsp;&nbsp;
<input type="radio" name="oper" id="role_del" value="role_del" onclick="oper_Chk(this)">删除&nbsp;&nbsp;
<input type="radio" name="oper" id="role_add" value="role_add" onclick="oper_Chk(this)">新增&nbsp;&nbsp;
<br><br>
<table  id="roles_table" border="1" cellspacing="0" cellpadding="0" width="700px">
  <tr>
  	<td rowspan="2" width="7%"><div align="center">序号</div></td>
  	<td rowspan="2" width="7%"><div align="center">选择</div></td>
    <td rowspan="2" width="8%"><div align="center">角色id</div></td>
    <td rowspan="2" width="25%"><div align="center">角色名称</div></td>
    <td colspan="6" width="53%"><div align="center">权限</div></td>

  </tr>
  <tr>
    <td><div align="center">浏览</div></td>
    <td><div align="center">发布</div></td>
    <td><div align="center">修改</div></td>
    <td><div align="center">审核</div></td>
    <td><div align="center">删除</div></td>
	<td><div align="center">管理</div></td>

  </tr>
  
<if condition="$role_arr">
<volist name='role_arr' id = 'v' key="k">
  <tr>
  	<td><div align="center">{$k}</div></td>
  	<td><div align="center"><input type="checkbox" name = "roles_row[]" value="{$v.1}" onclick="role_lock(this)" disabled></div></td>
    <td><div align="center">{$v.0}</div><input type="hidden" name="role_id" value="{$v.0}"></td>
    <td><div align="center">{$v.1}</div><input type="hidden" name="role_names" value="{$v.1}"></div></td>
<!--<{for($i = 2; $i < 8; $i++)}>-->
    <php>for($i=2;$i<=7;$i++):</php>
	<!--{$smarty.section.foo.index}-->
	<td><div align="center">
      <input type="checkbox" name="{$v.1}[]" id="{$v.1}[{$i-2}]" value="{$v[$i]}"
       <if condition="$v[$i] eq 1 " > checked='checked'</if> onclick="auth_Cho(this)" disabled>
    </div></td>
	<php>endfor;</php>
<!--<{/for}>-->
	<input type="hidden" id="{$v.1}_result" name="{$v.1}_result" value="">
  </tr>  
</volist>
</if>  
  <tr id="new_tr" style="display:none;">
  	<td><div align="center"></div></td>
  	<td><div align='center'><input type='checkbox' checked disabled></div></td>
  	<td></td>
  	<td>
  	  <div align='center'>
  	    <input type='text' name='new_name' id='new_name' value='' onblur='repeat_Chk(this)'>
  	    <input type='hidden' name='new_auth' id='new_auth' value=''>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='1' onclick='auth_Cho(this)' checked>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='0' onclick='auth_Cho(this)'>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='0' onclick='auth_Cho(this)'>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='0' onclick='auth_Cho(this)'>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='0' onclick='auth_Cho(this)'>
  	  </div>
  	</td>
  	<td>
  	  <div align='center'>
  	    <input type='checkbox' name='new_row[]' value='0' onclick='auth_Cho(this)'>
  	  </div>
  	</td>
  </tr>
</table>


</form>
<include file="Public:footer" />
